#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void GenerateMatrix(int n){
    vector<vector<int>> v(n,vector<int>(n,0));
    //矩阵的起始位置(0,0)
    int startx=0,starty=0;
    int i,j;
    int loop=n/2;
    int mid=n/2;
    int count=1,offset=1;
    while(loop--){
        //i表示行
        i=startx;
        //j表示列
        j=starty;
        for(j=starty;j<n-offset;++j){
            v[i][j]=count++;
        }
        for(i=startx;i<n-offset;++i){
            v[i][j]=count++;
        }
        for(;j>starty;--j){
            v[i][j]=count++;
        }
        for(;i>startx;--i){
            v[i][j]=count++;
        }
        //第二圈起始位置++
        startx++;
        starty++;

        offset++;
    }

    if(n%2){
        v[mid][mid]=count;
    }

    for(int c=0;c<v.size();++c){
        for_each(v[c].begin(),v[c].end(),[](int num){
            cout<<num<<" ";
        });
        cout<<endl;
    }

}

int main(){
    GenerateMatrix(3);
    return 0;
}